package me.fung.keen.common

import java.awt.Toolkit
import java.awt.datatransfer.Clipboard
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.StringSelection

object TextClipboard {
    private val clipboard: Clipboard = Toolkit.getDefaultToolkit().systemClipboard

    fun copy(text: String) {
        clipboard.setContents(StringSelection(text), null)
    }

    fun paste(): String {
        val result = clipboard.getContents(null).getTransferData(DataFlavor.stringFlavor)
        return result as? String ?: ""
    }
}